/**
 * 
 */
package org.jenkon.filter;

import java.util.regex.Pattern;

/**
 * Filter implementation for compare the value with a regular expression.
 * 
 * @author jkonopka
 * 
 */
public class StringRegexFilter implements Filter<String> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8601470897304981848L;

	private final Pattern pattern;

	/**
	 * @param pattern the pattern to check
	 */
	public StringRegexFilter(final String pattern) {
		this(Pattern.compile(pattern));
	}

	/**
	 * @param pattern the pattern to check
	 */
	public StringRegexFilter(final Pattern pattern) {
		this.pattern = pattern;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jenkon.commons.lang.filter.Filter#accept(java.lang.Object)
	 */
	public boolean accept(final String value) {
		return pattern.matcher(value).matches();
	}

}
